package com.base.myproject.client.HR.bcode;

import com.base.myproject.client.tools.Tools;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.BaseOpenJSP;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.Label;

/**
 * @author cxghiu410@gmail.com
 *	年度人员流失率统计
 */
public class Rpt_YearTurnover extends BaseJDBCPanel {
	DateField yearMonth = new DateField();
	Button search = new Button("查询");
	private Button toExcel = new Button("导出到EXCEL");
	String jspFile = "hr_Jsp/rptYearTurnover.jsp";  //默认的JSP页面
	public Rpt_YearTurnover() {
		init();
	}
	
	public void complete() {
		super.complete();
		print.addListener(Events.OnClick, getListener());
		getToolbarll().add(print);
		getToolbarll().add(toExcel);
		
	}
	
	BaseOpenJSP jsp;
	protected void init() {
		yearMonth.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy"));
		
		search.addListener(Events.OnClick, getListener());
		VerticalPanel vp = new VerticalPanel();
		HorizontalPanel hp = new HorizontalPanel();
		hp.setSpacing(10);
		hp.add(new Label("查询年度："));
		hp.add(yearMonth);
		hp.add(search);
		
		vp.add(hp);
		jsp = new BaseOpenJSP(jspFile);
		Tools.setResize(jsp, 0.99, 0.89);
		vp.add(jsp);
		add(vp);
	}

	Listener<BaseEvent> listener;
	private Listener<? extends BaseEvent> getListener() {
		if (listener != null) 
			return listener;
		listener = new Listener<BaseEvent>() {
			public void handleEvent(BaseEvent be) {
				if (be.getSource().equals(search)) {
					String year = yearMonth.getRawValue();
					if (year.equals("")) {
						MessageBox.alert("提示", "请选择查询年度，谢谢", null);
						return;
					}
					jsp.getFrame().setUrl(jspFile + "?year=" + year);
				} else {
					jsp.Print();
				}
			}
		};
		return listener;
	}
}
